<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="__STATIC__/js/jquery.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <script src="__STATIC__/bootstrap-table/js/bootstrap-table.js"></script>
    <script src="__STATIC__/bootstrap-table/js/bootstrap-table-zh-CN.min.js"></script>
    <script src="__STATIC__/bootstrap-table/js/dropdown.js"></script>
    <link rel="stylesheet" href="__STATIC__/bootstrap-table/css/bootstrap-table.min.css">
    <link rel="stylesheet" href="__STATIC__/bootstrap-table/css/bootstrap.css">
    <script type="text/javascript" src="__STATIC__/x-admin/js/xadmin.js"></script>
    <link rel="stylesheet" href="__STATIC__/x-admin/css/font.css">
    <link rel="stylesheet" href="__STATIC__/x-admin/css/xadmin.css">
</head>
<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="#">设备临时编号列表</a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="layui-row">
    <form class="layui-form layui-col-md12 x-so" onsubmit="return false">
        <input type="text" name="number"  placeholder="设备编号" autocomplete="off" style="width: 200px" class="layui-input">
        <div class="layui-input-inline">
            <select name="batch" id="batch">
                <option value="">批次号</option>
                {foreach $batch as $value}
                    <option value="{$value.batch}">{$value.batch}</option>
                {/foreach}
            </select>
        </div>
        <div class="layui-input-inline">
            <select name="version" id="version">
                <option value="">版本号</option>
                {foreach $batch as $value}
                    <option value="{$value.version}">{$value.version}</option>
                {/foreach}
            </select>
        </div>
        <button class="layui-btn"  id="search"><i class="layui-icon">&#xe615;</i></button>
    </form>
</div>
<xblock>
    <button class="layui-btn" id="generate">生成设备编号</button>
    <button class="layui-btn layui-btn-danger" id="del_all">删除</button>
    <button class="layui-btn layui-btn-primary" id="abandoning">弃用</button>
    <button class="layui-btn layui-btn-normal" id="export">导出excel</button>
    <button class="layui-btn layui-btn-warm" id="official_number">生成正式编号</button>
</xblock>
<table id="list">

</table>
</body>
<script>
    $('#list').bootstrapTable({
        //获取行号
        language: 'zh-CN',
        todayHighlight: true,
        striped: true,//设置为 true 会有隔行变色效果
        method: 'post',//服务器数据的请求方式 'get' or 'post'
        url: "{:url('/temporary_num/list')}",//服务器数据的加载地址
        toolbar:'#toolbar',//
        searchOnEnterKey:true,
        sortName:'ID',//排序字段
        sortOrder : 'desc',//降序
        sidePagination: "server",   //分页方式：client客户端分页，server服务端分页（*）
        pagination: 'false',//设置为 true 会在表格底部显示分页条
        pageSize: '15',//如果设置了分页，页面数据条数
        pageList:[15,30,50],
        smartDisplay:false,
        //得到查询的参数
        queryParams : function (params) {
            //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
            var temp = {
                rows: params.limit,                         //页面大小
                page: (params.offset / params.limit) + 1,   //页码
                sort: params.sort,      //排序列名
                sortOrder: params.order,//排位命令（desc，asc）
                searchName:$("input[name=number]").val(),
                batch:$("#batch option:selected").val(),
                version:$('#version option:selected').val()
            };
            return temp;
        },
        columns: [
            {title:'请选择',align:'center',checkbox : true},
            {field: 'id', title: 'ID', align:'center'},
            {field: 'number', title: '编号', align:'center'},
            {field: 'year', title: '生成年份', align:'center'},
            {field: 'batch', title: '批次', align:'center'},
            {field: 'version', title: '版本', align:'center'},
            {field: 'version_number', title: '版本号', align:'center'},
            {field: 'status', title: '状态', align:'center',formatter:status}
        ]}
    );
    //状态
    function status(val,rows){
        if(rows.status == 1){
            return '已用'
        }else{
            return "<span style='color: red'>已弃用</span>"
        }
    }
    //检索操作
    $("#search").click(function(){
        $("#list").bootstrapTable(('refresh'));
    });
    //弃用
    $("#abandoning").click(function () {
        layer.confirm('你确定要弃用吗',{btn:['确定','取消']},function(){
            var id = [];
            var info = $("#list").bootstrapTable('getSelections');
            for (var i=0;i<info.length;i++){
                id.push(info[i].id);
            }
            if(id.length == 0){
                layer.msg('请选择弃用的编号',{icon:5,time:2000})
                return
            }
            $.ajax({
                url:"{:url('/temporary_num/abandoning')}",
                type:"post",
                data:{
                    id:id
                },
                dataType:"json",
                success:function(res){
                    if(res.code){
                        layer.msg(res.msg,{icon:1,time:2000},function () {
                            $("#list").bootstrapTable(('refresh'));
                        });
                        return;
                    }else{
                        layer.msg(res.msg,{icon:5,time:2000});
                        return;
                    }
                }
            });
        });
    });
    //生成设备编号页面
    $("#generate").click(function () {
        layer.open({
            title:'生成设备临时编号',
            type:2,
            area:['460px','400px'],
            content:"{:url('/temporary_num/add')}"
        });
    });
    //批量删除
    $("#del_all").click(function () {
        layer.confirm('你确定要删除吗?',{btn:['确定','取消']},function () {
            var id = [];
            var info = $("#list").bootstrapTable('getSelections');
            for (var i=0;i<info.length;i++){
                id.push(info[i].id);
            }
            if(id.length == 0){
                layer.msg('请选择删除的编号',{icon:5,time:2000})
                return
            }
            $.ajax({
                url:"{:url('/temporary_num/delete')}",
                data:{id:id},
                type:"post",
                dataType:"json",
                success:function (res) {
                    if(res.code){
                        layer.msg(res.msg,{icon:1,time:2000},function(){
                            $('#list').bootstrapTable('remove', {
                                field: "id",
                                values: id
                            });
                        });
                        return;
                    }else{
                        layer.msg(res.msg,{icon:5,time:2000});
                        return;
                    }
                }
            });
        })
    });
    //导出excel
    $("#export").click(function () {
        layer.open({
            title:'导出excel',
            type:2,
            area:['400px','200px'],
            content:"{:url('/temporary_num/export')}"
        })
    })
    //生成正式编号
    $("#official_number").click(function () {
        layer.open({
            title:'生成正式编号',
            type:2,
            area:['400px','200px'],
            content:"{:url('/temporary_num/official')}"
        })
    })
</script>
</html>